<?php
/**
 * Created by IDEA.
 * User: dinesh
 * Date: Feb 24, 2012
 * Time: 11:58:16 AM
 * To change this template use File | Settings | File Templates.
 */


/**
 * The News Model does the back-end heavy lifting for the News Controller
 */
class News extends BaseModel {
    /**
     * Holds instance of database connection
     */
    private $db;

    public function __construct() {
        $this->db = new MysqlImprovedDriver;
    }

    /**
     * Fetches article based on supplied name
     *
     * @param string $author
     *
     * @return array $article
     */
    public function get_article($author) {
        //connect to database
        $this->db->connect();

        //sanitize data
        $author = $this->db->escape($author);

        //prepare query
        $this->db->prepare
        (
            "
        SELECT
            `date`,
            `title`,
            `content`,
            `author`
        FROM
            `articles`
        WHERE
            `author` = '$author'
        LIMIT
            1
        ;
        "
        );

        //execute query
        $this->db->query();

        $article = $this->db->fetch();

        return $article;
    }

    public function attributeNames() {
        // TODO: Implement attributeNames() method.
    }
}
 
